package com.itboye.lottery.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.itboye.lottery.base.BaseActivity;
import com.itboye.lottery.R;
import com.itboye.lottery.adapter.HistoryPrizeAdapter;
import com.itboye.lottery.bean.HistoryPrizeBean;
import com.itboye.lottery.enums.LotteryType;
import com.itboye.lottery.presenter.UserPresenter;
import com.itboye.lottery.retrofit.ResponseCallback;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class HistoryPrizeActivity extends BaseActivity implements ResponseCallback {

    RecyclerView rv_history_prize;
    UserPresenter userPresenter = new UserPresenter(this);
    ArrayList<HistoryPrizeBean.HistoryItem> historyPrizeBeanArrayList = new ArrayList<>();
    private HistoryPrizeAdapter adapter;
    LotteryType lotteryType;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_history_prize;
    }

    @Override
    protected void initData() {
        lotteryType = (LotteryType) getIntent().getSerializableExtra("type");
        rv_history_prize.setLayoutManager(new LinearLayoutManager(this));
        adapter = new HistoryPrizeAdapter(this, historyPrizeBeanArrayList);
        adapter.setOnItemClickListener((view, position) -> {
            startActivity(new Intent(HistoryPrizeActivity.this, Dlt_SsqPrizeDetailActivity.class)
                    .putExtra("type", lotteryType)
                    .putExtra("id", historyPrizeBeanArrayList.get(position).getId())
                    .putExtra("ball_type", "1")
                    .putExtra("open_time", historyPrizeBeanArrayList.get(position).getOpen_time()));
        });
        rv_history_prize.setAdapter(adapter);
        switch (lotteryType) {
            case SSQ:
                userPresenter.getSsqHistoryPrize();
                break;
            case DLT:
                userPresenter.getDltHistoryPrize();
                break;
        }
    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void success(@NotNull Object o, @NotNull String requestSuccessType) {
        historyPrizeBeanArrayList.addAll(((HistoryPrizeBean) o).getHis());
        adapter.notifyDataSetChanged();
    }

    @Override
    public void fail(int code, @NotNull Object msg, @NotNull String requestErrorType) {

    }
}
